package com.vincent.exam.sort;

public class BubbleSort {
    public void sort(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            for (int j = i+1;j<arr.length;j++){
                if (arr[i] > arr[j]){
                    swap(arr, i, j);
                }
            }
        }
    }

    public void swap(int[] arr, int a, int b){
        int temp = arr[a];
        arr[a] = arr[b];
        arr[b] = temp;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1,5,4,2,9,0,7,3,8};
        new BubbleSort().sort(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }
}
